<script setup lang="ts">
import { ref, inject } from "vue";
import { handleApply } from "@/service/api";
const visible = ref(false)
const defaultFrom = {
    id: 0,
    userId: 0,
    informationId: 0,
    appleDate: '',
    adminId: '',
    passFlag: 0,
    overruled: '',
    delFlag: 0
}
const getApplyList = inject<any>('getApplyList')
// 表单数据
const fromModel = ref({ ...defaultFrom });
//同意
const agree = () => {
    fromModel.value.passFlag = 1
    dealApply()
}
//驳回
const refuse = () => {
    fromModel.value.passFlag = 2
    visible.value = true
}
const open = (row: any) => {
    // visible.value = true
    fromModel.value.id = row.id
    fromModel.value.userId = row.userId
}
const dealApply = async () => {
    await handleApply(fromModel.value).then(res => {
        if (res.data.code === 200) {
            if (fromModel.value.passFlag === 1) {
                ElMessage.success('已同意！！！')
            }else if (fromModel.value.passFlag === 2){
                visible.value = false
                ElMessage.danger('已拒绝！！！')
            }
            getApplyList()
        } else {
            ElMessage.error('处理失败！！！')
        }
    }).catch(err => {
        console.log(err);
    })
}
defineExpose({
    open,
    agree,
    refuse
})
</script>

<template>
    <el-dialog v-model="visible">
        <el-form>
            <el-form-item label="驳回理由" prop="overruled">
                <el-input type="textarea" v-model="fromModel.overruled"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
                    <span>
                        <el-button @click="visible = false" style="margin-right: 10px;">取消</el-button>
                        <el-button type="primary" @click="dealApply">确定</el-button>
                    </span>
                </template>
    </el-dialog>
</template>

<style scoped lang="less"></style>